package com.sell.demo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sell.demo.entity.Good;
import com.sell.demo.mapper.good.GoodMapper;
import com.sell.demo.service.GoodService;
import com.sell.demo.util.IdUtil;

/**
 * 商品业务逻辑实现类
 *
 * Created by xchunzhao on 02/05/2017.
 */
@Service
public class GoodServiceImpl implements GoodService {

    @Autowired
    private GoodMapper goodMapper;

    /**
     * 获取商品列表信息
     * @param cityName
     */
    public List<Good> getGoodList(){
    	List<Good> goodList= goodMapper.getGoodList();
    	return goodList;
    }
    
    /**
     * 分页获取商品列表信息
     * @param cityName
     */
    public PageInfo<Good> getGoodListPage(int pageNum,int pageSize){
    	PageHelper.startPage(pageNum,pageSize);
    	List<Good> goodList= goodMapper.getGoodList();
    	PageInfo<Good> pageInfo = new PageInfo<Good>(goodList);
    	return pageInfo;
    }
    
    /**
     * 获取商品详情
     * @param 
     */
    public Good getGoodDetail(String id){
    	return goodMapper.getGoodDetail(id);
	}
	/**
     * 创建商品信息
     * @param good
     */
    public int createGood(Good good){
    	good.setId(IdUtil.getId());
    	return goodMapper.createGood(good);
    }
	
	/**
     * 更新商品信息
     * @param good
     */
    public int updateGood(Good good){
    	return goodMapper.updateGood(good);
    }
	
	/**
     * 删除商品信息
     * @param id
     */
    public int deleteGood(String id){
    	return goodMapper.deleteGood(id);
    }
	
	/**
     * 批量创建商品信息
     * @param goodList
     */
    public int createBatchGood(List<Good> goodList){
    	for(Good good:goodList){
    		good.setId(IdUtil.getId());
    	}
    	return goodMapper.createBatchGood(goodList);
    }
	
	/**
     * 批量更新商品信息
     * @param goodList
     */
    public int updateBatchGood(List<Good> goodList){
    	return goodMapper.updateBatchGood(goodList);
    }
	
	/**
     * 批量删除商品信息
     * @param ids
     */
    public int deleteBatchGood(String ids){
    	String[] ids_1 = ids.split(",");
    	return goodMapper.deleteBatchGood(ids_1);
    }

}
